package org.gpf.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import org.gpf.dao.ArticleOutlineDAO;
import org.gpf.po.ArticleOutline;
import org.gpf.util.DBUtil;

public class ArticleOutlineDAOImpl implements ArticleOutlineDAO{

	@Override
	public List<ArticleOutline> queryArticleOutlines(int page, int pageSize)
			throws Exception {
		List<ArticleOutline> articleOutlines = new ArrayList<>();
		
		String sql = "SELECT id,title,thumb,introduce FROM article_outline ORDER BY id DESC LIMIT ?,?";
		Connection conn = DBUtil.getConnection();
		PreparedStatement pstmt = conn.prepareStatement(sql);
		pstmt.setInt(1, page*pageSize);
		pstmt.setInt(2, pageSize);
		ResultSet rs = pstmt.executeQuery();
		while (rs.next()) {
			ArticleOutline articleOutline = new ArticleOutline();
			articleOutline.initFieldsFromResultSet(articleOutline, rs);
			articleOutlines.add(articleOutline);
		}
		return articleOutlines;
	}
	
	
}
